package com.inxedu.os.edu.service.system.impl;

import com.inxedu.os.edu.dao.SysFunctionMapper;
import com.inxedu.os.edu.pojo.SysFunction;
import com.inxedu.os.edu.pojo.SysFunctionExample;
import com.inxedu.os.edu.service.system.SystemFounctionService;
import com.sun.javafx.collections.MappingChange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SystemFounctionServiceImpl implements SystemFounctionService {
    @Autowired
    private SysFunctionMapper sysFunctionMapper;

    @Override
    public List<SysFunction> findSystrmFunctionAll() {

        List<SysFunction> functionList = sysFunctionMapper.selectSysFounctionAll();

        return functionList;
    }

    @Override
    public int addSystemFunction(SysFunction sysFunction) {
        int i = sysFunctionMapper.insert(sysFunction);

        return i;
    }

    @Override
    public int deleteSystemFunctionByid(String ids) {

        if(ids!=null && ids.trim().length()>0){
            if(ids.trim().endsWith(",")){
                ids = ids.trim().substring(0,ids.trim().length()-1);
            }
        }

        String[] split = ids.split(",");
        List<Integer> list=new ArrayList();
        for (int i=0;i<split.length;i++){
            list.add(Integer.parseInt(split[i]));

        }


        int i=sysFunctionMapper.deleteSystemFunctionByid(list);
        return i;
    }

    @Override
    public int updateSystemFunction(SysFunction sysFunction) {

        int i = sysFunctionMapper.updateByPrimaryKeySelective(sysFunction);

        return i;
    }

    @Override
    public int updateSystemFunctionByid(Integer parentId, Integer functionId) {
        SysFunction sysFunction=new SysFunction();
        sysFunction.setParentId(parentId);
        sysFunction.setFunctionId(functionId);

        int i = sysFunctionMapper.updateByPrimaryKeySelective(sysFunction);

        return i;
    }
}
